<template>
  <div class='container'>
    <el-dialog title="题目审核" :visible="dialogFormVisible" @close="close">
        <el-form :model="checkObj" ref="form" label-width="100px" :rules="rules">
          <el-form-item prop="chkRemarks">
            <el-radio-group v-model="checkObj.chkState">
              <el-radio :label="1">通过</el-radio>
              <el-radio :label="2">拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入审核意见"
              v-model="checkObj.chkRemarks">
            </el-input>
          </el-form-item>
        </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions.js'
export default {
  name: 'question-check',
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    checkId: {
      type: Number,
      default: null
    }
  },
  data () {
    const checkRemarks = (rule, value, callback) => {
      if (value === '') {
        this.$message.warning('请输入审核意见')
        return false
      } else {
        callback()
      }
    }
    return {
      checkObj: {
        id: null,
        chkState: 1,
        chkRemarks: ''
      },
      rules: {
        chkRemarks: [{ validator: checkRemarks, trigger: 'blur' }]
      }
    }
  },
  methods: {
    close () {
      this.checkObj = {
        id: null,
        chkState: 1,
        chkRemarks: ''
      }
      this.$refs.form.resetFields()
      this.$emit('close')
    },
    submit () {
      this.checkObj.id = this.checkId
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          await choiceCheck(this.checkObj)
          this.close()
          this.$message.success('操作成功')
        } else {
          // this.$message.warning('请输入审核意见')
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang='scss'>
::v-deep .el-form{
  padding-right: 80px !important;
}
</style>
